import { useLocation} from 'react-router-dom';

// 根据URL获取菜单的选中菜单Key
const useSelectedMenuKey = () => {
  const { pathname } = useLocation();
  let paths = pathname.split('/').filter((l) => l !== '');
  // 默认选中首页
  if(paths.length === 0) {
    paths = ['preface'];
  }

  return [paths[0]];
};

export default useSelectedMenuKey;
